package com.showcai.controller.distributor;

import com.showcai.controller.base.WeChatBaseController;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.result.ResultObj;
import com.showcai.result.ReturnCode;
import com.showcai.service.DistributorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Baggio on 2018-7-31.
 */
@Controller
@RequestMapping(value = "distributor")
public class DistributorController extends WeChatBaseController {
    @Autowired
    DistributorService distributorService;
    /**
     * 分销查询
     *
     * @return
     */
    @RequestMapping(value = "/distributorQuery")
    public ModelAndView distributorQuery() {
        ModelAndView mov = new ModelAndView();
        String views = "distributor/web/distributorQuery";
        if (getIsMobile()) {
            views = "distributor/wap/distributorQuery";
        }
        mov.setViewName(views);
        return mov;
    }
    /**
     * 分销量查询
     *
     * @return
     */
    @RequestMapping(value = "/getDistributionRequirements",  method = RequestMethod.POST)
    @ResponseBody
    public String getDistributionRequirements(String phone) {
        ResultObj resultObj = new ResultObj();

        try {
            resultObj.setData(distributorService.getDistributionRequirements(phone));
        } catch (MyRunTimeExcption myRunTimeExcption) {
            myRunTimeExcption.printStackTrace();
            resultObj.setMsg(myRunTimeExcption.getMessage());
        } catch (Exception e) {
            resultObj.setCode(ReturnCode.FAIL.getCode());
            e.printStackTrace();
            resultObj.setMsg(e.getMessage());
        }
        return resultObj.toJson();
    }


}
